import java.sql.Array;
import java.util.Locale;


class hh{
    int a;
    String b;

    public hh(int a, String b) {
        this.a = a;
        this.b = b;
    }

    @Override
    public String toString() {
        return "hh{" +
                "a=" + a +
                ", b='" + b + '\'' +
                '}';
    }
}

class hhh{
    final char[] h = {'1', '2', '2'};
}

public class Try {

    public static String to_lower(String args) {
        return args = args.toLowerCase();
    }

    public static int count(String s1) {
        //获得字符串的长度length();
        if (s1.isEmpty()) {
            return 0;
        }
        String[] hh = s1.split(" ");
        return hh.length;
    }


    public static void main(String[] args) {
        //StringBuilder StringBuffer 的方法
        StringBuffer hh = new StringBuffer();
        hh.append("hhHH");
        //字符串长度
        System.out.println(hh.length());
        //倒置字符串
        System.out.println(hh.reverse());
        //获取储存字符串的空间大小
        System.out.println(hh.capacity());
        //在指定位置插入字符串
        System.out.println(hh.insert(hh.indexOf("hh"), " HAHAHA "));
        //删除指定下表的字符
        System.out.println(hh.deleteCharAt(hh.indexOf(" ")));
        System.out.println("====");
        //删除某个区间的字符串，前闭后开
        System.out.println(hh.delete(hh.indexOf("h"), hh.lastIndexOf("h")));
        //替换某个区间的字符串，前闭后开
        System.out.println(hh.replace(hh.indexOf("A"), hh.lastIndexOf("H"), "WWWWWW"));
    }
    public static void mammin(String[] args) {
        //修改字符串
        String one = new String("hhhh");
        one = one + "HHHHhhh";
        System.out.println(one);

        //StringBuilder 类
        StringBuilder two = new StringBuilder("hhhh");
        for (char a = 'a'; a < 'z'; a++) {
            two.append(a);
        }
        System.out.println(two);

        //StringBuffer 类、
        StringBuffer three = new StringBuffer("haha");
        for (char a = 'a'; a < 'z'; a++) {
            three.append(a);
        }
        System.out.println(three);
        }
    public static void maibn(String[] args) {
        final char[] h = {'1', '2', '2'};
        System.out.println(h[0]);
        h[0] = 's';
        System.out.println(h[0]);
        hhh Hh = new hhh();
        System.out.println(Hh.h);
    }
    public static void mainad(String[] args) {
        String s = "S SS ss sS S ";
        s = "    ";
        System.out.println(to_lower(s));
        System.out.println(count(s));
    }

    public static void maina(String[] args) {
        //删除字符串头尾的空格
        String ha = "    h h h h h h   ";
        ha = ha.trim();
        System.out.println(ha);
    }

    public static void mainaaa(String[] args) {
        //字符串截取substring

        String hah = "hahhahahah";
        String s1 = hah.substring(4);//从4截取到尾
        System.out.println(s1);

        String s2 = hah.substring(2, 4);//截去从2到4
        System.out.println(s2);

        String ha = hah.substring(hah.indexOf("h"), hah.lastIndexOf("h"));
        System.out.println(ha);
    }

    public static void mainnmn(String[] args) {
        //拆分字符串split 会删除分割的那个字符
        String s1 = new String("hhhahhhahhh");
        String[] arr1 = s1.split("a");//以a全部分开
        for (String a : arr1
        ) {
            System.out.println(a);
        }
        System.out.println("====");
        String[] arr2 = s1.split("a", 2);//将arr2以a分为俩份
        for (String a : arr2
        ) {
            System.out.println(a);
        }
        System.out.println("====");
        //特殊字符的拆分. * + 前面要加上\\转义
        //若是\ 要用 \\\ 来转义
        //若有多个分割符号可用|
        String[] s3 = s1.split("a| |hh");
        for (String a : s3
        ) {
            System.out.print(a + " ");
        }
    }

    public static void mainmmaa(String[] args) {
        //格式化创建字符串format
        String s1 = String.format("%d-%.2f-%d", 22, 2.22, 22);
        System.out.println(s1);
    }

    public static void mainmam(String[] args) {
        //字符串转数组toCharArray
        String s1 = "hahahaha";
        char[] arr1 = s1.toCharArray();
        for (char x : arr1
        ) {
            System.out.print(x + " ");
        }

        //数组转字符串
        String s2 = new String(arr1);
        System.out.println(s2);
    }

    public static void maaain(String[] args) {
        //大小写转换

        String S1 = "HHHHH";
        String s1 = "hhhhhhh";

        //小写转大写toUpperCase
        System.out.println(s1.toUpperCase(Locale.ROOT));
        //大写转小写toLowerCase
        System.out.println(S1.toLowerCase());
    }

    public static void mainmma(String[] args) {
        //数字与字符串之间的装换

        //数字转字符串valueOf
        String s1 = String.valueOf(1234);
        String s2 = String.valueOf(true);
        String s3 = String.valueOf(new hh(123, "0000"));
        System.out.println(s1 + " aa s");
        //while (s2) {}
        System.out.println(s2);
        System.out.println(s3);//变为字符串了
        //System.out.println(11 + "ss");

        System.out.println("=====");
        //字符串转数字integer
        int a = Integer.parseInt("1234");
        Double b = Double.parseDouble("12.34");
        System.out.println(a);
        System.out.println(b);
    }

    public static void maiqqn(String[] args) {
        //字符串查找
        String one = "spare me indignity";

        //length()计算字符串的长度
        System.out.println(one.length());
        System.out.println("====");

        //返回参数对应的字符charAt
        System.out.println(one.charAt(2));

        //indexOf() 返回参数对应的下标 没有放回-1
        System.out.println(one.indexOf("a"));
        System.out.println(one.indexOf("ar"));
        System.out.println(one.indexOf("aaa"));
        System.out.println("====");
        System.out.println(one.indexOf('i', 7));//第下标7开始向右找
        System.out.println(one.indexOf('a', 3));//第下标7开始找
        System.out.println("====");
        //从后面往前面找lastIndexOf() spare me indignity
        System.out.println(one.lastIndexOf("y"));
        System.out.println(one.lastIndexOf("p", 3));//从这个下标开始往前找
    }

    public static void maixxn(String[] args) {
        //字符之间的比较

        //这样是直接比较储存的字符串
//        String one = "hh";
//        String two = "hh";
//        String three = one;
//        System.out.println(one == two);
//        System.out.println(one == three);

        //这样比较的是对象的地址
        String two = new String("hh");
        String one = new String("hh");
        String three = one;
        System.out.println(one == two);//false
        System.out.println(one == three);//true

        //用equals比较,比较储存的字符串，boolean类型
//        String one = new String("hh");
//        String two = new String("hh");
//        String three = one;
//        System.out.println(one.equals(two));//t
//        System.out.println(one.equals(one));//t

        //用compareTo比较 若有不相同的字符，返回俩字符之间的差值,小于0
        //如果之前有k个字符相同，者返回俩字符串长度的差值
//        String one = new String("abcd");
//        String two = new String("dbca");
//        String three = one;
//        System.out.println(one.compareTo(two));
//        System.out.println(one.compareTo(three));
        //忽略大小写比较 compareToIgnoreCase()
//        System.out.println(one.compareToIgnoreCase(two));
    }

    public static void mmain(String[] args) {
        //string初始化

        // new String对象
        String one = new String("hahaha");
        //直接使用常量字符串赋值
        String two = "hahah";
        //使用数组进行构造
        char[] arr = {'a', 'h', 'a', 'h', 'a', 'h'};
        String three = new String(arr);

        System.out.println(three);
    }
}
